package com.generalaj.console.configuration.workflow;

import java.util.*;

/**
 * Created by wangxin on 2017/2/27.
 */
public class GraphNode {
    private int uid;
    private String type;
    private String name;
    private Set<GraphNode> next;
    private Map<String,String> config;
    private GraphNode root;

    GraphNode(String type, String name) {
        this.type = type;
        this.name = name;
        this.root=this;
        this.uid=name.hashCode();
        this.next=new HashSet<GraphNode>();
        this.config=new HashMap<String, String>();
    }

    GraphNode(String type, String name,GraphNode root) {
        this(type,name);
        this.root=root;
    }

    public int getUid() {
        return uid;
    }


    public String getType() {
        return type;
    }

    public String getName() {
        return name;
    }

    public Set<GraphNode> getNext() {
        return next;
    }

    public void addAll(List<GraphNode> nexts) {
        this.next.addAll(nexts);
    }

    public void addNext(GraphNode next) {
        this.next.add(next);
    }

    public Map<String, String> getConfig() {
        return config;
    }
    public void updateConfig(String k,String v){
        this.config.put(k,v);
    }

    public GraphNode getRoot() {
        return root;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        GraphNode graphNode = (GraphNode) o;

        return getUid() == graphNode.getUid();

    }

    @Override
    public int hashCode() {
        return getUid();
    }

    @Override
    public String toString() {
        return "GraphNode{" +
                "type='" + type + '\'' +
                ", name='" + name + '\'' +
                '}';
    }
}
